Imports SchemaCodeGen
Imports System.Collections

Partial Class pages_connections_usercontrols_UCConnection : Inherits UserControl

#Region "Members"
    Private m_connection As CConnection
    Private m_sortedList As IList
#End Region

#Region "Interface"
    Public Sub Display(ByVal [connection] As CConnection, sortedList as IList)
        If Parent.Controls.Count Mod 2 = 0 Then row.Attributes.Add("class", "alt_row")

        m_connection = [connection]
        m_sortedList = sortedList

        With m_connection
            litNumber.Text = CStr(sortedList.IndexOf(m_connection) + 1)
			litConnectionSetId.Text = .TemplateSet.FullName
			lnkConnectionName.Text =  CStr(IIF(.ConnectionName.Length = 0, "...", .ConnectionName))
            lnkConnectionName.NavigateUrl = CSitemap.ConnectionEdit(.ConnectionId)
            litConnectionUserName.Text = .ConnectionUserName
			litConnectionDriverId.Text = .DriverType.DriverName
			litConnectionString.Text = .ConnectionString
            litConnectionPassword.Text = .ConnectionPassword
            litConnectionOutputDir.Text = .ConnectionOutputDir
            litConnectionNameSpace.Text = .ConnectionNameSpace
            chkConnectionUseAuditTrail.Checked = .ConnectionUseAuditTrail
            chkConnectionUseCaching.Checked = .ConnectionUseCaching
			litConnectionTablePrefix.Text = .ConnectionTablePrefix
			litConnectionCreated.Text = CUtilities.Timespan(.ConnectionCreated)
			litConnectionCreated.ToolTip = CUtilities.LongDateTime(.ConnectionCreated)
			lnkEntityCount.Text = CUtilities.CountSummary(.EntityCount, "entity")
			lnkSchemaCount.Text = CUtilities.CountSummary(.SchemaCount_, "snapshot")
		End With
    End Sub
#End Region

#Region "Event Handlers"
    Private Sub chkConnectionUseAuditTrail_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles chkConnectionUseAuditTrail.CheckedChanged
        With m_connection
            .ConnectionUseAuditTrail = chkConnectionUseAuditTrail.Checked
            .Save()
        End With
        Refresh()
    End Sub
    Private Sub chkConnectionUseCaching_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles chkConnectionUseCaching.CheckedChanged
        With m_connection
            .ConnectionUseCaching = chkConnectionUseCaching.Checked
            .Save()
        End With
        Refresh()
    End Sub
    Private Sub btnDelete_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btnDelete.Click
        m_connection.Delete()
        Refresh()
    End Sub
#End Region

#Region "Private"
    Private Sub Refresh()
        'CCache.ClearCache()

        'If False Then 'Request.RawUrl.ToLower.Contains("myparent.aspx") Then
        '    'Special case: Parent entity owns the list
        '    Response.Redirect(CSitemap.MyParentEdit(m_connection.ConnectionParentId, MyParent.ETab.connections, m_pageIndex)
        'Else
        '    'Normal case: Search page owns the list
            Response.Redirect(Request.RawUrl) 'includes paging info
        'End If 
    End Sub
#End Region

End Class
